/**
 * 
 */
package com.mindtree.vi.presentation.servlet;

import com.mindtree.vi.business.javaservice.StatusCode;
import com.mindtree.vi.business.user.UserManager;
import com.mindtree.vi.dbaccess.datatypes.user.User;
import com.mindtree.vi.dbaccess.datatypes.user.UserCredential;
import com.mindtree.vi.dbaccess.datatypes.user.UserRole;
import com.mindtree.vi.presentation.annotation.ReferencedBy;
import com.mindtree.vi.xml.XmlUserRegisterRequest;
import com.mindtree.vi.xml.XmlUserRegisterResponse;

/**
 * @author m1005309
 * 
 */
public class UserRegisterServlet extends
		BaseHttpServlet<XmlUserRegisterRequest, XmlUserRegisterResponse> {

	@ReferencedBy("userManager")
	private UserManager userManager;

	@Override
	public void process() {
		XmlUserRegisterRequest request = getRequest();

		User user = new User();
		user.setEmailId(request.getEmailId());
		user.setFirstName(request.getFirstName());
		user.setLastName(request.getLastName());
		user.setRole(UserRole.valueOf(request.getRole()));
		UserCredential credential = new UserCredential();
		credential.setUserCredentialId(request.getEmailId());
		credential.setPassword(request.getPassword());
		user.setCredential(credential);
		userManager.registerUser(user);
		XmlUserRegisterResponse response = new XmlUserRegisterResponse();
		response.setEmailId(user.getEmailId());
		response.setUserId(user.getId());
		response.setPassword(user.getCredential().getPassword());
		response.setMessage("Successfully registered!!!");
		response.setStatusCode(StatusCode.COMPILE_SUCCESS);
		setResponse(response);
	}
}
